/**	
 * <br>
 * Copyright 2011 Chuan. All rights reserved.<br>
 * <br>			 
 * Package: com.chuan.mantu.utils <br>
 * FileName: ConnectionDetector.java <br>
 * <br>
 * @version
 * @author javacyc@qq.com
 * @created 2013-1-15
 * @last Modified 
 * @history
 */

package com.chuan.mantu.utils;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;

/**
 * {网络监测}
 *  
 *  @author javacyc@qq.com
 *  @created 2013-1-15 下午03:10:05
 *  @lastModified       
 *  @history           
 */

public class ConnectionDetector {

	private Context context;
	
	public ConnectionDetector(Context context) {
		this.context = context;
	}
	
	public boolean isConnection(){
		ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Activity.CONNECTIVITY_SERVICE);
		boolean wifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
		boolean mobile = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
		return wifi | mobile;
	}
	
	public boolean isMobileConnection(){
		ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Activity.CONNECTIVITY_SERVICE);
		boolean mobile = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
		return mobile;
	}
	
	public boolean isWifiConnection(){
		ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Activity.CONNECTIVITY_SERVICE);
		boolean wifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
		return wifi;
	}
}